const MyResponseModel = require('../model/MyResponseModel')

// 公共函数,统一处理 promise 操作;
async function __common(promise) {
  const responseModel = new MyResponseModel()
  await promise
    .then(successful => {
        if(successful){
            responseModel.ok = true
            responseModel.data = successful
        }else {
            responseModel.message = 'db not find data'
        }
    })
    .catch((lose) => {
      // 异常分两大类:  1-执行时出错   2-数据库未启动
      responseModel.message = 'db error or not start db'
      responseModel.sys_message = lose.errorResponse || { reason: 'DB not start' }
    })
  return responseModel
}

module.exports = __common